/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.beans.Users;
import com.metier.UsersMetier;

/**
 *
 * @author top
 */
public class panelModifierUtilisateurs extends javax.swing.JPanel {
	private String loginUserToModifi="";
	private String profilToModifi="";
	private String valeurSelectionner;

    /**
     * Creates new form panelAjouterUtilisateurs
     */
    public panelModifierUtilisateurs() {
       // initComponents();
    }
    public panelModifierUtilisateurs( JButton buttonAnnuler){
    	initComponents(buttonAnnuler);
    	
    	
    	
    	
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents(JButton bouttonAnnuler) {

        jLabel1 = new javax.swing.JLabel();
        textNom = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        textPrenom = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        textLogin = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        textPasswords = new javax.swing.JPasswordField();
        jLabel5 = new javax.swing.JLabel();
        textEmail = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        textPhone = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textAdresse = new javax.swing.JTextArea();
        labelProfil = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        boutonValider = new javax.swing.JButton();
        boutonAnnuler = new javax.swing.JButton();
        textProfil = new javax.swing.JComboBox();

        setBackground(new java.awt.Color(128, 130, 133));
        setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(103, 153, 255)));
        setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        setMaximumSize(new java.awt.Dimension(1050,375 ));
        setMinimumSize(new java.awt.Dimension(1050, 375));
        setPreferredSize(new java.awt.Dimension(1056, 410));

        jLabel1.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        jLabel1.setText("Nom :");
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));

        textNom.setFont(new java.awt.Font("Verdana", 3, 12)); // NOI18N

        jLabel2.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        jLabel2.setText("Prenom :");
        textPrenom.setFont(new java.awt.Font("Verdana", 3, 12));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));

        jLabel3.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        jLabel3.setText("Login :");
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));

        textLogin.setFont(new java.awt.Font("Verdana", 3, 12)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        jLabel4.setText("Passwords :");
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));

      // textPasswords.setEditable(false);
        textPasswords.setFont(new java.awt.Font("Verdana", 3, 12)); // NOI18N
        

        jLabel5.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        jLabel5.setText("Email  :");
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));

        textEmail.setFont(new java.awt.Font("Verdana", 3, 12)); // NOI18N

        jLabel6.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        jLabel6.setText(" Phone :");
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));

        textPhone.setFont(new java.awt.Font("Verdana", 3, 12)); // NOI18N

        jLabel7.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        jLabel7.setText(" Profil :");
        jLabel7.setForeground(new java.awt.Color(255, 255, 255));

        jLabel8.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        jLabel8.setText("Adresse :");
        jLabel8.setForeground(new java.awt.Color(255, 255, 255));

        textAdresse.setColumns(20);
        textAdresse.setFont(new java.awt.Font("Verdana", 3, 12)); // NOI18N
        textAdresse.setRows(5);
        jScrollPane1.setViewportView(textAdresse);

        labelProfil.setIcon(new javax.swing.ImageIcon("src/main/java/com/photos/profil.gif")); // NOI18N

        jLabel10.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        jLabel10.setText("Photo de Profil");
        jLabel10.setForeground(new java.awt.Color(255, 255, 255));

        boutonValider.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        boutonValider.setText("VALIDER");
        boutonValider.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	if (JOptionPane.showConfirmDialog(getFrame(),
						"Voulez-vous vraiment confirmer la modification?",
						"Information", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            	  UsersMetier usrMetier=new UsersMetier();
            	  Users userModify=new Users();
            	  String loginCorrespondant=getLoginUserToModifi();
            	 System.out.println("voici le login correspondant à l'utilisateur mofifié     "  +loginCorrespondant);
            	userModify=usrMetier.findUserByLogin(loginCorrespondant);
            	userModify.setUsrNom(textNom.getText());
            	userModify.setUsrPrenom(textPrenom.getText());
            	userModify.setUsrLogin(textLogin.getText());
            	userModify.setUsrPhone(textPhone.getText());
            	userModify.setUsrAdresse(textAdresse.getText());
            	userModify.setUsrEmail(textEmail.getText());
            	userModify.setUsrPasswd(textPasswords.getText());
            	userModify.setUsrProfil((String)textProfil.getSelectedItem());
            	usrMetier.testUpdate(userModify);
            	textAdresse.getText();
		        textPhone.setText("");
		        textAdresse.setText("");
		        textEmail.setText("");
		        textNom.setText("");
		        textLogin.setText("");
		        textPrenom.setText("");
		        textPhone.setText("");
		      JOptionPane.showMessageDialog(null, "La modification a été bien enregistré ");
                
               
            	}     
            }
        });

        boutonAnnuler.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
        boutonAnnuler.setText("ANNULER");
        boutonAnnuler.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				PanelConsultant pan=new PanelConsultant();
				pan.setVisible(true);
			    
				pan.tableauListUsers();
				pan.getPanelbas().add(new JScrollPane(pan.tableListeUsers), BorderLayout.CENTER);
				validate();
        
				
				
			
			}
		});
        textProfil.setPreferredSize(new Dimension(100, 20));
        textProfil.addItem("Profil");
        textProfil.addItem("Administrateur");
        textProfil.addItem("Agent Commercial");
        textProfil.addItem("Comptable");
        textProfil.addItem("Consultant");
        textProfil.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				valeurSelectionner= (String) textProfil.getSelectedItem();
			}
		});
        textProfil.addFocusListener(new FocusListener() {
			
			public void focusLost(FocusEvent arg0) {//quand le composant perd le focus
				// TODO Auto-generated method stub
				
				
			}
			
			public void focusGained(FocusEvent arg0) {//quand le composant prend le focus
				// TODO Auto-generated method stub
				
			}
		});
        
        

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(textNom)
                            .addComponent(textPrenom)
                            .addComponent(textLogin)
                            .addComponent(textPasswords, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
                            .addComponent(textEmail))
                        .addGap(72, 72, 72)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))
                        .addGap(18, 18, 18))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(boutonValider)
                        .addGap(96, 96, 96)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(textPhone, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(textProfil, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(75, 75, 75)
                                .addComponent(labelProfil)
                                .addContainerGap(79, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(88, 88, 88))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(64, 64, 64)
                        .addComponent(bouttonAnnuler)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textNom, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(36, 36, 36)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textPrenom, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textProfil, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(textLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(textPasswords, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(textEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(24, 24, 24)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(77, 77, 77)
                        .addComponent(labelProfil, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel10)))
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bouttonAnnuler)
                    .addComponent(boutonValider))
                .addContainerGap(38, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void boutonValiderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boutonValiderActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_boutonValiderActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton boutonAnnuler;
    private javax.swing.JButton boutonValider;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel labelProfil;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea textAdresse;
    private javax.swing.JTextField textEmail;
    private javax.swing.JTextField textLogin;
    private javax.swing.JTextField textNom;
    private javax.swing.JPasswordField textPasswords;
    private javax.swing.JTextField textPhone;
    private javax.swing.JTextField textPrenom;
    private javax.swing.JComboBox textProfil;
    // End of variables declaration//GEN-END:variables
	public javax.swing.JTextArea getTextAdresse() {
		return textAdresse;
	}

	public void setTextAdresse(javax.swing.JTextArea textAdresse) {
		this.textAdresse = textAdresse;
	}

	public javax.swing.JTextField getTextEmail() {
		return textEmail;
	}

	public void setTextEmail(javax.swing.JTextField textEmail) {
		this.textEmail = textEmail;
	}

	public javax.swing.JTextField getTextLogin() {
		return textLogin;
	}

	public void setTextLogin(javax.swing.JTextField textLogin) {
		this.textLogin = textLogin;
	}

	public javax.swing.JTextField getTextNom() {
		return textNom;
	}

	public void setTextNom(javax.swing.JTextField textNom) {
		this.textNom = textNom;
	}

	public javax.swing.JPasswordField getTextPasswords() {
		return textPasswords;
	}

	public void setTextPasswords(javax.swing.JPasswordField textPasswords) {
		this.textPasswords = textPasswords;
	}

	public javax.swing.JTextField getTextPhone() {
		return textPhone;
	}

	public void setTextPhone(javax.swing.JTextField textPhone) {
		this.textPhone = textPhone;
	}

	public javax.swing.JTextField getTextPrenom() {
		return textPrenom;
	}

	public void setTextPrenom(javax.swing.JTextField textPrenom) {
		this.textPrenom = textPrenom;
	}

	

	/**
	 * @return the textProfil
	 */
	public javax.swing.JComboBox getTextProfil() {
		return textProfil;
	}

	/**
	 * @param textProfil the textProfil to set
	 */
	public void setTextProfil(javax.swing.JComboBox textProfil) {
		this.textProfil = textProfil;
	}

	public javax.swing.JButton getBoutonValider() {
		return boutonValider;
	}

	public void setBoutonValider(javax.swing.JButton boutonValider) {
		this.boutonValider = boutonValider;
	}
	public JPanel getFrame() {
		return this;
	}


	/**
	 * @return the boutonAnnuler
	 */
	public javax.swing.JButton getBoutonAnnuler() {
		return boutonAnnuler;
	}

	/**
	 * @param boutonAnnuler the boutonAnnuler to set
	 */
	public void setBoutonAnnuler(javax.swing.JButton boutonAnnuler) {
		this.boutonAnnuler = boutonAnnuler;
	}

	public javax.swing.JLabel getLabelProfil() {
		return labelProfil;
	}

	public void setLabelProfil(javax.swing.JLabel labelProfil) {
		this.labelProfil = labelProfil;
	}

	public String getLoginUserToModifi() {
		return loginUserToModifi;
	}

	public void setLoginUserToModifi(String loginUserToModifi) {
		this.loginUserToModifi = loginUserToModifi;
	}
	public String getProfilToModifi() {
		return profilToModifi;
	}
	public void setProfilToModifi(String profilToModifi) {
		this.profilToModifi = profilToModifi;
	}
	public String getValeurSelectionner() {
		return valeurSelectionner;
	}
	public void setValeurSelectionner(String valeurSelectionner) {
		this.valeurSelectionner = valeurSelectionner;
	}
	


    
}
